function [QValuesSave, AbsorptionSave] = Spara4Sensing(runIDs, ParameterRange, FrequencySelectRange, PolarizedDirection, FileTag, SaveFlag, WhichPeak)
    % 从当前打开的CST窗口，获取S参数，计算Q值和吸收值，保存在CST所在文件位置
    %
    % @since 2022.4.14
    % @param  [runIDs] runID向量.
    % @param  [ParameterRange] 对应的参数值变化范围.
    % @param  [FrequencySelectRange] 需要计算Q值的范围.
    % @param  [PolarizedDirection] 极化方向.
    % @param  [FileTag] 保存文件名中加入的标志.
    % @param  [SaveFlag] 是否保存文件，保存则不为0.
    % @param  [WhichPeak] 所选频率范围有两个峰是，计算第一个(-1)还是第二个(其他值).
    % @return  [QValuesSave] Q值，ID，和参数值.
    % @return  [AbsorptionSave] 频率与各个参数对应的吸收值.
    %
    % 使用案例1：
    %    无参数调用， [~,~] = Spara2QandA()
    %    将按runID返回所有值，Q值默认计算第一个峰，默认频率范围请查看
    %    极化方向为Y，不保存文件
    % 使用案例2：
    %    [~,~]=Spara2QandA(1:31,-85:5:60,[1.1,1.3],'Y','Full_Dx',0,-1)
    %

    %     close all;
    CST_Post = CST_MicrowaveStudio();

    if nargin == 0
        runIDs = CST_Post.getRunIDs;
        FrequencySelectRange = [1, 2];
        PolarizedDirection = 'Y';
        FileTag = [];
        SaveFlag = 0;
        WhichPeak = 1;

    end

    % [~, runIDStrings] = CST_Post.getRunIDs();
    % runIDStrings = erase(runIDStrings, '3D:RunID:');
    % runIDStrings = str2num(char(runIDStrings));
    % ParameterRange = runIDStrings(runIDs);

    QValuesSave = [];
    AbsorptionSave = [];

    for everyrun = runIDs
        % fprintf('\n------本次处理的是runID:%i------------ \n', everyrun);

        [freq, sparam, ~] = CST_Post.getSParams(everyrun);

        if PolarizedDirection == 'Y'
            [pParameters, Output_Abp] = ObtainPeakParameters(sparam, freq, FrequencySelectRange);

        elseif PolarizedDirection == 'X'
            [pParameters, Output_Abp] = ObtainPeakParameters(sparam(:, 5:6), freq, FrequencySelectRange);
        end

        if WhichPeak == 'ALL'
            Qvalue = pParameters.Qvalue;
            locs = pParameters.locs;

            QValueSave = [QValuesSave; Qvalue, everyrun];
            locsSave = [QValuesSave; locs, everyrun];
        else

            try

                Qvalue = pParameters.Qvalue(WhichPeak);
                locs = pParameters.locs(WhichPeak);

                QValueSave = [QValuesSave; Qvalue, everyrun];
                locsSave = [QValuesSave; locs, everyrun];
            catch
                fprintf('输入峰的参数有误！');
            end

        end

        AbsorptionSave = [AbsorptionSave, Output_Abp];
        fprintf(' runID:%d ----------- Q_Value:%f \n', everyrun, Qvalue);

    end

    %-----------------
    figure;
    plot(1:length(runIDs), QValueSave(:, 1), 'r*-', 'linewidth', 2);
    %     xlim([runIDs(1) runIDs(end)]);
    set(gca, 'xtick', 1:length(runIDs));
    set(gca, 'XTickLabel', ParameterRange);
    figure;
    contourf(AbsorptionSave);

    %-----------------
    if SaveFlag

        SaveFile([freq, AbsorptionSave], [CST_Post.folder, '\Fre_Absorption_', FileTag, ], 'txt');
        %         SaveFile( [CST_Post.folder, '\Fre_Absorption_', FileTag, ], 'txt');
        SaveFile([QValuesSave, ParameterRange'], [CST_Post.folder, '\Q_', FileTag], 'txt');
        disp(['文件保存成功！'])
    end

    function [peakParameters, Absorption] = ObtainPeakParameters(sparam, freq, FrequencySelectRange)
        Absorption = abs(sparam(:, 1)).^2 + abs(sparam(:, 2)).^2; % 其实是反射

        IndicsRange = find(FrequencySelectRange(1) <= freq & FrequencySelectRange(2) >= freq);
        SelectedPeak = Absorption(IndicsRange);
        SelectedFreq = freq(IndicsRange);
        clearvars sparm freq IndicsRange

        try

            [pks, locs, width, ~] = findpeaks(SelectedPeak, SelectedFreq, 'widthreference', 'halfheight');
            peakParameters = struct;

            locs(1); % 看一下是否为空
        catch ME

            if (strcmp(ME.identifier, 'MATLAB:badsubscript'))
                fprintf('*\n*\n*\n索引超出范围，具体请查看峰的形状（已经将Q值取为INf)*\n*\n*\n')
                Q_Value = Inf;

            else
                peakParameters.pks = pks;
                peakParameters.locs = locs;
                peakParameters.width = width;
                peakParameters.Qvalue = locs ./ width;

            end

        end

    end

end
